import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal } from 'antd';
import {fetchData} from '../../../components/AjaxConsumer'

export default class ListProHandOutOrderPage extends Component{
    constructor(props) {
        super(props);
        //行操作列表-已弃用
        this.rowOperation = [
            
        ];
        //header 操作列表111
        this.headerOperation = [

        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'handOutOrderId',
            data: [
                // {
                //     showName: 'handOutId',
                //     columnName: 'handOutId',
                //     columnHidden:true,
                //     foreverHidden: true
                // },
                {
                    showName: '机号',
                    columnName: 'machineNumber',
                    showOption: []
                }, {
                    showName: '发货单号',
                    columnName: 'handOutNo',
                    columnWidth: 130
                }, {
                    showName: '发货日期',
                    columnName: 'scanTimeEnd'
                }, {
                    showName: '货主',
                    columnName: 'userDefined1',
                    showOption: []
                },
                {
                    showName: '型号',
                    columnName: 'model',
                    columnWidth: 120
                }, {
                    showName: '定量',
                    columnName: 'density'
                }, {
                    showName: '规格',
                    columnName: 'spec'
                }, {
                    showName: '仓库',
                    columnName: 'waCode',
                    showOption: []
                }, {
                    showName: '品名',
                    columnName: 'productName',
                    columnWidth: 100 
                },
                // {
                //     showName: '类型',
                //     columnName: 'type',
                //     showOption: [
                //         {
                //             optionKey: '0',
                //             optionShow: '正品'
                //         },{
                //             optionKey: '1',
                //             optionShow: '样品'
                //         }
                //     ]
                // },
                {
                    showName: '等级',
                    columnName: 'grade',
                    showOption: [
                        {
                            optionKey: '1',
                            optionShow: '一等品'
                        },{
                            optionKey: '2',
                            optionShow: '二等品'
                        },{
                            optionKey: '3',
                            optionShow: '处理品'
                        }
                    ]
                }, {
                    showName: '级别',
                    columnName: 'level'
                }, {
                    showName: '单位',
                    columnName: 'unit',
                    columnWidth: 100
                }, {
                    showName: '实发数量',
                    columnName: 'codeNum',
                    columnWidth: 100
                }, {
                    showName: '实发重量',
                    columnName: 'codeWt',
                    columnWidth: 100
                }, {
                    showName: '经办人',
                    columnName: 'userDefined5',
                    columnWidth: 120
                }, {
                    showName: '车牌',
                    columnName: 'userDefined2'
                }
                // , {
                //     showName: '箱号',
                //     columnName: 'userDefined3'
                // }, {
                //     showName: '最后修改时间',
                //     columnName: 'gmtModified',
                //     columnWidth: 150
                // }
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                showName: '生产机号',
                name: 'machineNumber',
                type: 'select',
                optionList: []
                // url:'/base/dic/get/machine_number'
            }, {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList: [//下拉框的信息
                      {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            }, {
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList: [//下拉框的信息
                      {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'A',
                        optionShow:'A'
                    },{
                        optionKey:'B',
                        optionShow:'B'
                    },{
                        optionKey:'C',
                        optionShow:'C'
                    },{
                        optionKey:'D',
                        optionShow:'D'
                    }
                ]
            },{
                showName: '仓库',
                name: 'waCode',
                type: 'select',
                optionList: []
                // url: '/base/data/area/get/wa_code'
            }, {
                showName:'扫描结束时间',
                name:'scanTimeEnd',
                type: 'date',
                maxName:'scanTimeEndMax',
                minName:'scanTimeEndMin',
                // showTime: '1'
            }, {
                showName:'实发数量',
                name:'codeNum',
                type:'number',
                maxName:'codeNumMax',
                minName:'codeNumMin'
            }, {
                showName:'实发重量',
                name:'codeWt',
                type:'number',
                maxName:'codeWtMax',
                minName:'codeWtMin'
            }, {
                showName: '货主',
                name: 'userDefined1',
                type: 'select',
                optionList: []
            }, {
                showName: '单位',
                name: 'unit',
                type: 'select',
                url:'/base/dic/get/unit'
            },
            // {
            //     showName:'创建时间',
            //     name:'gmtCreate',
            //     type: 'date',
            //     maxName:'gmtCreateMax',
            //     minName:'gmtCreateMin',
            //     showTime: '1'
            // },{
            //     showName:'最后修改时间',
            //     name:'gmtModified',
            //     type: 'date',
            //     maxName:'gmtModifiedMax',
            //     minName:'gmtModifiedMin',
            //     showTime: '1'
            // }
        ];

    }

    componentWillMount() {
        const options= {
            url: '/base/data/purchase/getPurchase',
            type: 'get',
            condition:{}
        };
        //先写死，后面再改
        fetchData(this, options, this.purchaseInitCallBackHandle);

        const machineOptions = {
            url: '/base/dic/get/machine_number',
            type: 'get'
        }
        fetchData(this, machineOptions, this.dicInitCallBackHandle);

        const waCodeOptions = {
            url: '/base/data/area/get/wa_code',
            type: 'get'
        }
        fetchData(this, waCodeOptions, this.waCodeInitCallbackHandle);
    }
    //下拉框 初始化
    purchaseInitCallBackHandle = (resData)=>{
        // alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.purchaseCode;
            tmp.optionShow = e.purchaseName;
            optionList.push(tmp);
        });
        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[3].showOption = optionList;
        this.searchComponentData[7].optionList = optionList;
    }
    dicInitCallBackHandle = (resData)=>{
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = Number(e.dicCode);
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        this.tableColumn.data[0].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
    }
    waCodeInitCallbackHandle = (resData)=>{
        // alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });
        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[7].showOption = optionList;
        this.searchComponentData[3].optionList = optionList;
    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'exp'){
            // this.expHandle(rowObj);
        }
    }
    editHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updatePage.editHandle(rowObj);
        }
    };

    //按照库位新增
    addHandle = () => {
        this.refs.addPage.addHandle();
    };

    //刷新列表
    refreshHandle = () => {
        this.refs.proHandOutListOrder.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'proHandOutListOrder'
                    title="手工出库统计"
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/product/handSn/outOrder'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
            </div>
        )
        
    }

}